package com.dts.evaluate.ui.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dts.evaluate.R;
import com.dts.evaluate.bean.ProjectDataBean;
import com.dts.evaluate.common.Constants;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 办事指南-》基本信息
 * A simple {@link Fragment} subclass.
 * Use the {@link BasicInfoFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class BasicInfoFragment extends BaseFragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @Bind(R.id.textview1)
    TextView textview1;
    @Bind(R.id.textview2)
    TextView textview2;
    @Bind(R.id.textview3)
    TextView textview3;
    @Bind(R.id.textview4)
    TextView textview4;
    @Bind(R.id.textview5)
    TextView textview5;
    @Bind(R.id.textview6)
    TextView textview6;
    @Bind(R.id.textview7)
    TextView textview7;

    // TODO: Rename and change types of parameters
    private ProjectDataBean.ApproveProjectBean mParam1;
    private String mParam2;


    public BasicInfoFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment BasisFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static BasicInfoFragment newInstance(ProjectDataBean.ApproveProjectBean param1, String param2) {
        BasicInfoFragment fragment = new BasicInfoFragment();
        Bundle args = new Bundle();
        args.putSerializable(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = (ProjectDataBean.ApproveProjectBean) getArguments().getSerializable(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_basic_info, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData(mParam1);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    /**
     * 初始化基本信息
     * @param approveProjectBean
     */
    private void initData(ProjectDataBean.ApproveProjectBean approveProjectBean) {

        String appAddress = approveProjectBean.getAppAddress();
        int id = approveProjectBean.getId();
        int appIsCharge = approveProjectBean.getAppIsCharge();
        int appIsInGsc = approveProjectBean.getAppIsInGsc();
        int appLimitDay = approveProjectBean.getAppLimitDay();
        String appMethod = approveProjectBean.getAppMethod();
        String appNote = approveProjectBean.getAppNote();
        String appProjectCodeId = approveProjectBean.getAppprojectcodeid();
        int appPromissLimitDay = approveProjectBean.getAppPromisesLimitDay();
        String appProjectName = approveProjectBean.getAppprojectname();
        String character = approveProjectBean.getCharacter();
        final int maxDay = approveProjectBean.getMaxday();
        final String timeLimit = approveProjectBean.getTimelimit();

        //获取基本信息
        if (Constants.Character.GOV_APPROVE.equals(character)) {
            character = Constants.Character.GOV_APPROVE_VALUE;
        } else if (Constants.Character.PUB_APPROVE.equals(character)) {
            character = Constants.Character.PUB_APPROVE_VALUE;
        } else {
            character = Constants.Character.OTHER_APPROVE_VALUE;
        }
        textview1.setText(character);
        if ("instants".equals(timeLimit)) {
            textview2.setText(R.string.current);
        } else {
            textview2.setText(R.string.promiss);
        }
        String workDayString = getString(R.string.work_day);
        textview3.setText(appLimitDay + workDayString);
        textview4.setText(appPromissLimitDay + workDayString);
        textview5.setText(maxDay + workDayString);
        if (Constants.AppMethod.AFFIRM.equals(appMethod)) {
            appMethod = Constants.AppMethod.AFFIRM_VALUE;
        } else if (Constants.AppMethod.AUDITIONG.equals(appMethod)) {
            appMethod = Constants.AppMethod.AUDITIONG_VALUE;
        } else if (Constants.AppMethod.INSPECT_REPORT.equals(appMethod)) {
            appMethod = Constants.AppMethod.INSPECT_REPORT_VALUE;
        } else if (Constants.AppMethod.KEEP_ARCHIVE.equals(appMethod)) {
            appMethod = Constants.AppMethod.KEEP_ARCHIVE_VALUE;
        } else if (Constants.AppMethod.TRANSITDTELEGRAM.equals(appMethod)) {
            appMethod = Constants.AppMethod.TRANSITDTELEGRAM_VALUE;
        }
        textview6.setText(appMethod);
        if (appIsInGsc == 0) {
            textview7.setText(R.string.no);
        } else {
            textview7.setText(R.string.yes);
        }
    }
}
